<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function jsonSuccess($msg)
{
	echo json_encode([
			'code' => 1,
			'msg' => $msg
	],JSON_UNESCAPED_UNICODE);
}

function jsonError($msg)
{
	echo json_encode([
			'code' => 0,
			'msg' => $msg
	],JSON_UNESCAPED_UNICODE);
}

function jsonOther($code,$msg)
{
	echo json_encode([
			'code' => $code,
			'msg' => $msg
	],JSON_UNESCAPED_UNICODE);
}
function idcard_verify_number($idcard_base){
    if (strlen($idcard_base) != 17){
        return false;
    }
    $factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //debug 加权因子
    $verify_number_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'); //debug 校验码对应值
    $checksum = 0;
    for ($i = 0; $i < strlen($idcard_base); $i++){
        $checksum += substr($idcard_base, $i, 1) * $factor[$i];
    }
    $mod = $checksum % 11;
    $verify_number = $verify_number_list[$mod];
    return $verify_number;
}
